package com.huaxin.hxcloud.find.view;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.huaxin.common.Entity.InfoType;
import com.huaxin.hxcloud.R;
import com.huaxin.hxcloud.activity.NewsListActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hebing on 2017/5/15.
 */

public class TopAdapter2 extends RecyclerView.Adapter<TopAdapter2.TopViewHolder> {
    private List<InfoType> _topTypes = new ArrayList();

    public List<InfoType> getDatas() {
        if (_topTypes == null)
            _topTypes = new ArrayList();
        return _topTypes;
    }

    public void setDatas(List<InfoType> datas) {
        this._topTypes = datas;
    }

    private Context context;

    public TopAdapter2(Context context) {
        this.context = context;
    }

    @Override
    public TopAdapter2.TopViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new TopAdapter2.TopViewHolder(LayoutInflater.from(context).inflate(R.layout.item_top_info, parent, false));
    }

    @Override
    public void onBindViewHolder(TopAdapter2.TopViewHolder holder, final int position) {
        final InfoType data = _topTypes.get(position);
        holder.tv1.setText(data.getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NewsListActivity.start(context, data);
            }
        });
        Glide.with(context).load(data.getImg()).apply(new RequestOptions().error(R.drawable.head_portrait)).into(holder.ci1);

        /*Glide.with(context).load(data.getImg())
                .error(R.drawable.head_portrait)
                .into(holder.ci1);*/

    }

    @Override
    public int getItemCount() {
        return _topTypes == null ? 0 : _topTypes.size();
    }

    public class TopViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.ci1)
        ImageView ci1;
        @BindView(R.id.tv1)
        TextView tv1;
        View itemView;

        public TopViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }
}
